package com.ruoyi.framework.interceptor.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.framework.interceptor.InterfaceTokenCheckInterceptor;
import com.ruoyi.framework.redis.RedisCache;
import com.ruoyi.project.app.domain.AppCustomer;
import com.ruoyi.project.app.service.IAppCustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * 小程序端接口token校验
 *
 * @author ruoyi
 */
@Component
public class InterfaceTokenCheckInterceptorImpl extends InterfaceTokenCheckInterceptor {

    @Autowired
    private RedisCache redisCache;
    @Autowired
    private IAppCustomerService appCustomerService;

    @SuppressWarnings("unchecked")
    @Override
    public boolean okToken(HttpServletRequest request) {
        String token = request.getHeader("token");
//      Object openid = redisCache.getCacheObject(token);
        AppCustomer openid = appCustomerService.getOne(new QueryWrapper<AppCustomer>()
                .eq("token", token).eq("if_deleted","0"));
        if (openid == null) {
            return false;
        }
        return true;
    }
}
